home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / Sources C- WorkDisk V.adf / iff / plopsound1.c < prev    next >
C/C++ Source or Header  |  1987-02-15  |  5KB  |  227 lines

  1. #include    <exec/types.h>
  2. #include     <exec/nodes.h>
  3. #include    <exec/libraries.h>
  4. #include        <exec/memory.h> /* soundprod */
  5.  
  6. #include    <graphics/gfx.h>
  7. #include    <graphics/rastport.h>
  8. #include    <graphics/text.h>
  9. #include    <intuition/intuition.h>
  10. #include     <stdio.h> /* ook voor soundprod */
  11. #include     "df1:iff/jiff.c"
  12.  
  13. #include "hardware/custom.h" /* soundprod */
  14.  
  15.  
  16.  
  17. LONG filesize,s1,s2,per;
  18. char *filename;
  19. short *sndbuffer;
  20.  
  21.  
  22. /*This should be in exec/libraries.h */
  23. extern struct Library *OpenLibrary();
  24.  
  25. /*This should be in intuition/intuition.h */
  26. extern struct Screen *OpenScreen();
  27.  
  28. /* These are the bases for the libraries you need to do any graphics
  29.    much at all and still multi-task */
  30. struct Library *GfxBase = NULL;
  31. struct Library *LayersBase = NULL;
  32. struct Library    *IntuitionBase = NULL;
  33.  
  34. /* Well the workbench Screen isn't 320x200x5 so...*/
  35. struct Screen *PlopScreen = NULL;
  36.  
  37. /* Just one font for me... not static cause you might want it
  38.    in your menu modules. */
  39. struct TextAttr PlopFont =
  40.     {
  41.     "topaz.font",  /* I think this is the ROM font */
  42.     8,
  43.     0,
  44.     0,
  45.     };
  46.  
  47. /* a NewScreen - I don't know what half of this means either */
  48. static
  49. struct NewScreen PlopNewScreen =
  50.     {
  51.     0, 0, XMAX, YMAX, PLANES,
  52.     0, 1,
  53.     0,
  54.     CUSTOMSCREEN,
  55.     &PlopFont,
  56.     "Plop on Top",
  57.     NULL,
  58.     NULL,
  59.     };
  60.  
  61. /* To use clip blit need a RastPort.  Pretty useless, a BitMap should
  62.    be enough I think ... or anyway something a little less massive */
  63. struct RastPort PlopRastPort;
  64.  
  65. void
  66. put_ea_cmap(cmap, colors)
  67. unsigned char *cmap;
  68. long colors;
  69. {
  70. long i;
  71. unsigned long r, g, b;
  72.  
  73. if (colors > 32)    /*color clipping*/
  74.     colors = 32;
  75.  
  76. /* This loop is modified to work with Aztec 3.4a 32bit by J. Van Houtven */
  77. /* Modification Date : 20 July 1987 */
  78.  
  79. for (i=0; i<colors; i++)
  80.     {
  81.          r= *cmap++ >> 4;
  82.          g= *cmap++ >> 4;
  83.          b= *cmap++ >> 4;
  84.          SetRGB4(&PlopScreen->ViewPort,i,(long)r,(long)g,(long)b);
  85.     }
  86. }
  87.  
  88. /* back out backwards */
  89. void
  90. plop_cleanup()
  91. {
  92. custom.dmacon = 0x0003;
  93. if(sndbuffer)
  94.         FreeMem(sndbuffer,filesize);
  95. if (PlopScreen != NULL)
  96.     CloseScreen(PlopScreen);
  97. if (IntuitionBase != NULL)
  98.     CloseLibrary(IntuitionBase);
  99. if (LayersBase != NULL)
  100.     CloseLibrary(LayersBase);
  101. if (GfxBase != NULL)
  102.     CloseLibrary(GfxBase);
  103. }
  104.  
  105. main(argc, argv)
  106. int argc;
  107. char *argv[];
  108. {
  109. int i,j,x,y;
  110. struct ILBM_info *info;
  111.  
  112. /* aanroep van sound routine */
  113. per = 280;
  114. filename = "TAON_1";
  115. filesize = 42676;
  116. MakeSound();
  117.  
  118.  
  119. if ((GfxBase =  OpenLibrary("graphics.library", (long)0)) == NULL)
  120.         return(-1);
  121.  
  122. if ((LayersBase =  OpenLibrary("layers.library", (long)0)) == NULL)
  123.     {
  124.     plop_cleanup();
  125.     return(-2);
  126.     }
  127.  
  128. if ((IntuitionBase =  OpenLibrary("intuition.library",(long) 0)) == NULL)
  129.     {
  130.     plop_cleanup();
  131.     return(-3);
  132.     }
  133.  
  134. if ( (PlopScreen = OpenScreen(&PlopNewScreen) ) == NULL)
  135.     {
  136.     plop_cleanup();
  137.     return(-4);
  138.     }
  139.  
  140. InitRastPort(&PlopRastPort);
  141. PlopRastPort.Mask = (1<<PLANES)-1;
  142. /*just play it safe in case someone tries to load 6 bit planes...*/
  143.  
  144. for (i=1; i<argc; i++)
  145. {
  146.  if ( (info = read_iff(argv[i], 0) ) != NULL)
  147.  {
  148.   put_ea_cmap(&info->cmap, (1 << info->bitmap.Depth));
  149.   PlopRastPort.BitMap = &info->bitmap;
  150.   ClipBlit( &PlopRastPort, (long)0, (long)0,
  151.            &PlopScreen->RastPort, (long)info->header.x, (long)info->header.y,
  152.        (long)info->header.w, (long)info->header.h, (long)COPY_MINTERM);
  153.   Delay( (long)360);  /*pause for a couple seconds */
  154.  
  155.   y = YMAX-1;
  156.   for(j=0;j<80;j++)
  157.   {
  158.    x=j<<2;
  159.    ScrollRaster(&PlopScreen->RastPort,0L,j-40L,x,0L,x+3L,y);
  160.   }
  161.  
  162.   Delay( (long)300);
  163.  
  164.   SetAPen(&PlopScreen->RastPort,0);
  165.   for(j=0;j<100;j++)
  166.   {
  167.    Move(&PlopScreen->RastPort,0,j);Draw(&PlopScreen->RastPort,XMAX-1,j);
  168.    Move(&PlopScreen->RastPort,0,YMAX-1-j);Draw(&PlopScreen->RastPort,XMAX-1,YMAX-1-j);
  169.   }
  170.  
  171.   free_planes(&info->bitmap);
  172.   }
  173.  }
  174. plop_cleanup();
  175. }
  176. /* ====== end of main ======= */
  177.  
  178. MakeSound()
  179. {
  180. LoadSound();
  181. PlaySong();
  182. }  
  183.  
  184. LoadSound()
  185. {
  186. FILE *fopen(), *fp;
  187. SHORT *ptr;
  188. LONG i;
  189.  
  190. sndbuffer = AllocMem(filesize,MEMF_CHIP);
  191. ptr = sndbuffer;
  192.  
  193. custom . dmacon = 0x0003;
  194. fp = fopen(filename,"r");
  195. if (fp == NULL) return(0);
  196.  
  197. s1 = 0; s2 =filesize;
  198. for (i=0; i<s1; i++)
  199.     getc(fp);
  200.  
  201. for (i=s1/2; i<s2/2; i++)
  202.     {
  203.     *ptr++ = getc(fp)*256 + getc(fp);
  204.     }
  205.  
  206. fclose (fp);
  207. }
  208.  
  209. PlaySong()
  210. {
  211. custom . aud[0].ac_ptr = (UWORD *)sndbuffer;
  212. custom . aud[0].ac_len = s2/2-s1/2;
  213. custom . aud[0].ac_per = per;
  214. custom . aud[0].ac_vol = 64;
  215.  
  216. custom . aud[1].ac_ptr = (UWORD *)sndbuffer;
  217. custom . aud[1].ac_len = s2/2-s1/2;
  218. custom . aud[1].ac_per = per;
  219. custom . aud[1].ac_vol = 64;
  220.  
  221. custom . dmacon = 0x8203;
  222. }
  223.  
  224.  
  225.  
  226.  
  227.